# = test.admin.16.rb -  New  Photo Gallery  Test
# 
# See LICENSE.txt for licensing details.
#
#To test the functionality for setting the properties for a new photo gallery.
require 'watir'
require 'watir/WindowHelper'
include Watir
require 'test/unit'
require '../watir.config.rb'
require '../resources/functions.rb'

class TC_PhotosCreateAlbum_test < Test::Unit::TestCase
    
    def startup			
      $GalleryName = randomChar(15)
      @@ie = Watir::IE.start($SITE_URL)
    end
  
    def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
    end

    def test_01_verifyHomeText
      assert(ie.contains_text(/Community Server/))	
    end
      
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end
    
    def test_03_navigateToLogin
      ie.link(:text, 'Sign in').click
      assert(ie.contains_text("Sign in name"))
    end
	  
	  def test_04_populateLoginForm
      ie.text_field(:id, /username$/).value = $ADMIN_USER
      assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
      
      ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
      assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
	  end
	  
    def test_05_submitLoginForm
      ie.link(:id, /loginButton$/).click
      test_01_verifyHomeText
    end
    
    def test_06_verifyControlPanel
      assert(ie.link(:text, /Control Panel/).exists?)
      ie.link(:text, /Control Panel/).click
      assert(ie.contains_text(/Community Server Announcements/))      
    end
    
    def test_07_verifyControlPanelTabBarLinks
      assert_equal $SITE_URL + 'controlpanel/default.aspx', ie.link(:text, 'Dashboard').href
      assert_equal $SITE_URL + 'controlpanel/blogs', ie.link(:text, 'My Blogs').href
      assert_equal $SITE_URL + 'controlpanel/photos/', ie.link(:text, 'My Photos').href
      assert_equal $SITE_URL + 'controlpanel/files', ie.link(:text, 'My Files').href
      assert_equal $SITE_URL + 'controlpanel/moderation', ie.link(:text, 'Forums Moderation').href
      assert_equal $SITE_URL + 'controlpanel/Setup.aspx', ie.link(:text, 'Administration').href
      assert_equal $SITE_URL + 'controlpanel/Reporting/default.aspx', ie.link(:text, 'Reporting').href
    end
    
    def test_08_navigateVerifyMyPhotosDashboard
      ie.link(:text, 'My Photos').click
      assert(ie.contains_text("My Photos Dashboard"))
      assert(ie.contains_text("Current Photo Gallery"))   
    end
    
    def test_09_navigateToCreateGalleryPage
      ie.goto($SITE_URL + 'controlpanel/photoadmin/SectionEdit.aspx?tab=gallery')
      assert(ie.contains_text("New Gallery"))
    end
    
    def test_10_verifyLinksExistOnCreateGalleryPage
      assert(ie.link(:text, 'Help').exists?)
      assert(ie.link(:text, 'Inbox').exists?)
      assert(ie.link(:text, 'Exit Control Panel and Return to Site').exists?)
      assert(ie.link(:text, 'Dashboard').exists?)
      assert(ie.link(:text, 'My Blogs').exists?)
      assert(ie.link(:text, 'My Photos').exists?)
      assert(ie.link(:text, 'My Files').exists?)
      assert(ie.link(:text, 'Forums Moderation').exists?)
      assert(ie.link(:text, 'Administration').exists?)
      assert(ie.link(:text, 'Reporting').exists?)
      assert(ie.link(:text, 'Create New Gallery').exists?)
      assert(ie.link(:text, 'Gallery Groups').exists?)
      assert(ie.link(:text, 'Galleries').exists?)
      assert(ie.link(:text, 'Global Permissions').exists?)
      assert(ie.link(:text, 'Global Storage Quotas').exists?)
      assert(ie.link(:text, 'Default Photo Settings').exists?)
      #assert(ie.link(:text, 'Default Presentation').exists?)
      assert(ie.link(:id, /SectionDetails1_Helpicon6$/).exists?)
      assert(ie.link(:id, /SectionDetails1_Helpicon4$/).exists?)
      assert(ie.link(:id, /SectionDetails1_Helpicon5$/).exists?)
      assert(ie.link(:id, /SectionDetails1_Helpicon2$/).exists?)
      assert(ie.link(:id, /SectionDetails1_HelpIcon1$/).exists?)
      assert(ie.link(:id, /SectionDetails1_Helpicon3$/).exists?)
      assert(ie.link(:id, /SectionDetails1_Helpicon9$/).exists?)
      assert(ie.link(:id, /SectionDetails1_HelpIcon1$/).exists?)
      assert(ie.link(:id, /Layout1_Helpicon3$/).exists?)
      assert(ie.link(:id, /Layout1_Helpicon4$/).exists?)
      assert(ie.link(:id, /Quotas1_Helpicon7$/).exists?)
      assert(ie.link(:id, /Quotas1_Helpicon8$/).exists?)
      assert(ie.link(:id, /Quotas1_Helpicon9$/).exists?)
      assert(ie.link(:id, /TaskRegion_SaveButton$/).exists?)
      assert(ie.link(:url, 'http://communityserver.org/r.ashx?2').exists?)
      assert(ie.link(:text, 'Telligent').exists?)
    end
    
    def test_11_verifyFieldsExistOnCreateGalleryPage
      assert(ie.select_list(:id, /SectionDetails1_AdminGroupList$/).exists?)
      assert(ie.select_list(:id, /SectionDetails1_DefaultLanguage$/).exists?)
      #assert(ie.select_list(:id, /Skin1_Themes$/).exists?)
      assert(ie.select_list(:id, /Layout1_PicturesSortBy$/).exists?)
      assert(ie.radio(:id, /ynIsActive_0$/).exists?)
      assert(ie.radio(:id, /ynIsActive_1$/).exists?)
      assert(ie.radio(:id, /ynIsSearchable_0$/).exists?)
      assert(ie.radio(:id, /ynIsSearchable_1$/).exists?)
      assert(ie.text_field(:id, /SectionDetails1_SectionName$/).exists?)
      assert(ie.text_field(:id, /SectionDetails1_AppKey$/).exists?)
      assert(ie.text_field(:id, /SectionDetails1_Owners$/).exists?)
      assert(ie.text_field(:id, /Layout1_PictureListingColumns$/).exists?)
      assert(ie.text_field(:id, /Layout1_PictureListingRows$/).exists?)
      assert(ie.text_field(:id, /Quotas1_ImageQuota$/).exists?)
      assert(ie.text_field(:id, /Quotas1_DiskQuota$/).exists?)
    end
    
    def test_12_createNewGallery
      ie.text_field(:id, /SectionDetails1_SectionName$/).value = $GalleryName
      ie.link(:id, /TaskRegion_SaveButton$/).click
      
      assert(ie.contains_text("Galleries"))
      assert(ie.contains_text("Choose a gallery to manage from the list below"))
      assert(ie.link(:text, $GalleryName).exists?)
    end

end